package org.webdb.core.database;

import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;

public class SimpleRecord implements Record {

    private Map<String, Object> fields = new LinkedHashMap<String, Object>(10);

    public SimpleRecord setField(String fieldName, String value) {
        fields.put(fieldName, value);
        return this;
    }

    @Override
    public String toString() {
        return "SimpleRecord(" + fields.toString() + ")@"
                + Integer.toHexString(super.hashCode());
    }

    @Override
    public Set<Entry<String, Object>> fieldEntrySet() {
        return Collections.unmodifiableSet(fields.entrySet());
    }

    @Override
    public void close() throws IOException {
        throw new UnsupportedOperationException();
    }

    @Override
    public Object getField(String fieldName) {
        return fields.get(fieldName);
    }
    
    @Override
    public boolean isEmpty() {
        return fields.isEmpty();
    }
}
